home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / gengetopt-2.6.lha / gengetopt-2.6 / txtc.sh.in < prev   
Text File  |  2001-03-20  |  4KB  |  116 lines

  1. # Copyright (C) 1998 Eleftherios Gkioulekas <lf@amath.washington.edu>
  2. #  
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. # GNU General Public License for more details.
  11. # You should have received a copy of the GNU General Public License
  12. # along with this program; if not, write to the Free Software 
  13. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. #
  15. # As a special exception to the GNU General Public License, if you 
  16. # distribute this file as part of a program that contains a configuration 
  17. # script generated by Autoconf, you may include it under the same 
  18. # distribution terms that you use for the rest of that program.
  19.  
  20.  
  21. # Usage:
  22. # 1. To produce object files for a bunch of text files:
  23. #      sh txtc.sh foo1.txt foo2.txt foo3.txt ...
  24. # 2. To produce only C files for a bunch of text files:
  25. #      sh txtc.sh -c foo1.txt foo2.txt foo3.txt ...
  26. # 3. To produce pic object files object files
  27. #      sh txtc.sh -l libtool foo1.txt foo2.txt foo3.txt ...
  28.  
  29. # ---------------------------------------------
  30. # These definitions are imported from Autoconf
  31. # ---------------------------------------------
  32.  
  33. CC="@CC@"
  34. AWK="@AWK@"
  35.  
  36. # --------------------
  37. # Initialize the data 
  38. # --------------------
  39.  
  40. # File names
  41. text_files=""
  42. path_to_libtool=""
  43.  
  44. # Flags
  45. only_the_c_files="no"
  46.  
  47.  
  48. # ------------------------------------------
  49. # Now parse the options and update the state
  50. # ------------------------------------------
  51.  
  52. while test -n "$1"
  53. do
  54.   argument="$1"
  55.   case $argument in
  56.   -c)  only_the_c_files="yes"
  57.        ;;
  58.   -l)  shift
  59.        path_to_libtool="$1"
  60.        ;;
  61.   *)   text_files="$text_files $1"
  62.        ;;
  63.   esac
  64.   shift
  65. done
  66.  
  67. # ---------------------------------
  68. # Now look over all the text files
  69. # ---------------------------------
  70.  
  71. for file in $text_files
  72. do
  73.   # Get the filenames for C, object and pic object files
  74.   c_file="`echo $file  | sed 's/\.[a-zA-Z]*$/.c/g'  | $AWK -F/ '{ print $NF }'`"
  75.   o_file="`echo $file  | sed 's/\.[a-zA-Z]*$/.o/g'  | $AWK -F/ '{ print $NF }'`"
  76.   lo_file="`echo $file | sed 's/\.[a-zA-Z]*$/.lo/g' | $AWK -F/ '{ print $NF }'`"
  77.  
  78.   # Get the symbol name for the file and the length
  79.   symbol_name="`echo $file | sed 's/\./_/g' | $AWK -F/ '{ print $NF }'`"
  80.   file_length="`cat $file | wc -l`"
  81.  
  82.   # Create the C file
  83.   # First apply the following substitutions with sed
  84.   # 1. Escape the escapes
  85.   # 2. Escape the quotes
  86.   # 3. Nuke whitespace after the last character
  87.   # Then pipe through awk to make the C program
  88.   # FIXME: perhaps another substitution needed for tabs?
  89.   rm -f $c_file
  90.   cat $file | sed 's/\\/\\\\/g
  91.                    s/\"/\\\"/g
  92.                    s/[[:blank:]]*$//g' | 
  93.               $AWK -v symbol_name="$symbol_name" -v file_length="$file_length" \
  94.                    -v filename="$file"  '
  95.      BEGIN { print "#define NULL (char *) 0"
  96.              print "int " symbol_name "_length = " file_length ";"
  97.              print "char *" symbol_name "[] = { " 
  98.              print "  \"" filename "\"," }
  99.  
  100.            { print "  \"" $0 "\"," }
  101.  
  102.      END   { print "  NULL }; " }
  103.   ' > $c_file
  104.  
  105.   # If we also want to build an object file, do so here 
  106.   # FIXME: At the moment I am not supporting shared libraries
  107.   # Will do so once I get a stable version.
  108.   if test "$only_the_c_files" = "no"
  109.   then
  110.     $CC $CFLAGS -c $c_file
  111.     rm -f $c_file
  112.   fi
  113. done
  114.